import JointConfig from "./joint-config";
import Vec3 from "../../common/vec3";
import SpringDamper from "./spring-damper";
import RotationalLimitMotor from "./rotational-limit-motor";
import Method from "../../common/method";

export default class RagdollJointConfig extends JointConfig{
    constructor() {
        super();
        this.localTwistAxis1 = new Vec3(1,0,0);
        this.localTwistAxis2 = new Vec3(1,0,0);
        this.localSwingAxis1 = new Vec3(0,1,0);
        this.twistSpringDamper = new SpringDamper();
        this.swingSpringDamper = new SpringDamper();
        this.twistLimitMotor = new RotationalLimitMotor();
        this.maxSwingAngle1 = 3.14159265358979;
        this.maxSwingAngle2 = 3.14159265358979;
    }
    init(rigidBody1,rigidBody2,_worldAnchor,_worldTwistAxis,_worldSwingAxis) {
        let worldAnchor=Method.convertVec3(_worldAnchor), worldTwistAxis=Method.convertVec3(_worldTwistAxis).elements,worldSwingAxis=Method.convertVec3(_worldSwingAxis).elements;
        this._init(rigidBody1,rigidBody2,worldAnchor);
        Method.inverseTransformVec3(rigidBody1._transform.elements,worldTwistAxis,1,this.localTwistAxis1.elements);
        Method.inverseTransformVec3(rigidBody2._transform.elements,worldTwistAxis,1,this.localTwistAxis2.elements);
        Method.inverseTransformVec3(rigidBody1._transform.elements,worldSwingAxis,1,this.localSwingAxis1.elements);
        return this;
    }
}